unit Unit36; 

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, sqldb, db,
  DBGrids, Unit1;

type

  { TForm36 }

  TForm36 = class(TForm)
    Datasource1: TDatasource;
    DBGrid1: TDBGrid;
    SQLQuery1: TSQLQuery;
    procedure DBGrid1CellClick(Column: TColumn);
    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    procedure FormShow(Sender: TObject);
  private
    { private declarations }
  public
    codigo : string;
    nombre : string;
    cuit : string;
    iva : string;
    direccion : string;
    region : string;
  end; 

var
  Form36: TForm36; 

implementation

{ TForm36 }

procedure TForm36.FormShow(Sender: TObject);
var
  cliente : String;
  
begin
  codigo := '';
  nombre := '';
  cuit := '';
  direccion := '';
  iva := '';
  region := '';
  
  if SQLQuery1.Active = True then
    SQLQuery1.Close;
    
  cliente := InputBox('Busqueda de Código de Cliente', 'Ingrese parte del nombre del cliente:', '');
  
  if cliente <> '' then
  begin
  SQLQuery1.DataBase := Form1.PQConnection1;
  SQLQuery1.Transaction := Form1.SQLTransaction1;
  SQLQuery1.SQL.Text := 'select cln_cdg, cln_nombre, cln_cuit, cln_iva, cln_direccion, cln_region '
    + 'from cliente where cln_nombre ilike ''%' + cliente + '%'' order by cln_nombre';
    
  SQLQuery1.Open;
  
  DBGrid1.Columns[0].Title.Caption := 'Código';
  DBGrid1.Columns[1].Title.Caption := 'Nombre';
  DBGrid1.Columns[2].Title.Caption := 'CUIT';
  DBGrid1.Columns[3].Title.Caption := 'I.V.A.';
  DBGrid1.Columns[4].Title.Caption := 'Dirección';
  DBGrid1.Columns[5].Title.Caption := 'Región';
  
  DBGrid1.Columns[0].Width := 50;
  DBGrid1.Columns[1].Width := 145;
  DBGrid1.Columns[2].Width := 85;
  DBGrid1.Columns[3].Width := 35;
  DBGrid1.Columns[4].Width := 170;
  DBGrid1.Columns[5].Width := 80;
  end
  else
    Close;
end;

procedure TForm36.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
  if SQLQuery1.Active = True then
    SQLQuery1.Close;
end;

procedure TForm36.DBGrid1CellClick(Column: TColumn);
begin
  codigo := SQLQuery1.FieldByName('cln_cdg').AsString;
  nombre := SQLQuery1.FieldByName('cln_nombre').AsString;
  cuit := SQLQuery1.FieldByName('cln_cuit').AsString;
  iva := SQLQuery1.FieldByName('cln_iva').AsString;
  direccion := SQLQuery1.FieldByName('cln_direccion').AsString;
  region := SQLQuery1.FieldByName('cln_region').AsString;
  Close;
end;

initialization
  {$I unit36.lrs}

end.

